package cn.yunyichina.provider.reservation.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Lullaby on 2016/8/31.
 */
public class DateUtil {

    public static final String YYYYMMDD = "yyyy-MM-dd";
    public static final String YYYYMMDDHH = "yyyy-MM-dd HH";
    public static final String YYYYMMDDHHMM = "yyyy-MM-dd HH:mm";
    public static final String YYYYMMDDHHMMSS = "yyyy-MM-dd HH:mm:ss";

    public static final String YYYYMMDDHHMMSS_NOBAR = "yyyyMMddHHmmss";

    private static final DateFormat YYYYMMDD_FORMATTER = new SimpleDateFormat(YYYYMMDD);

    public static String format(Date date, String pattern) {
        DateFormat formatter = new SimpleDateFormat(pattern);
        return formatter.format(date);
    }

    public static String getTodayString() {
        DateFormat formatter = new SimpleDateFormat(YYYYMMDD);
        return formatter.format(Calendar.getInstance().getTime());
    }

    public static String getPastDateString(int interval) {
        DateFormat formatter = new SimpleDateFormat(YYYYMMDD);
        Calendar calendar = Calendar.getInstance();
        calendar.set(
                calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH),
                calendar.get(Calendar.DAY_OF_MONTH) - interval);
        return formatter.format(calendar.getTime());
    }

}
